﻿using System;
using Selenium;

namespace Quail
{
    /// <summary>
    /// A browser that does absolutely nothing.  Useful for creating test shells that really have no need for a browser, but you want to perform Quail logging.
    /// </summary>
    public class EmptyBrowser : IWebBrowser
    {
        private readonly TestSession _session;
        private readonly EmptyPage _page;

        public EmptyBrowser(TestSession session)
        {
            _session = session;
            _page = new EmptyPage(this);
            Timeout = 30000;
        }

        public int Timeout
        {
            get; set;
        }

        public bool SilentLogging
        {
            get; set;
        }

        public Task ActiveTask
        {
            get { return _session.ActiveTask; }
        }

        public string Location
        {
            get { return string.Empty; }
        }

        public Uri LocationUri
        {
            get { return null; }
        }

        public IDisposable CacheLocation()
        {
            return new DumbCache();
        }

        public TestStopwatch GetStopwatch()
        {
            return new TestStopwatch(Timeout);
        }

        public IWebPage GenericPage
        {
            get { return _page; }
            set { throw new NotSupportedException(); }
        }

        public ISelenium SeleniumInterface
        {
            get { throw new NotSupportedException(); }
        }

        /// <summary>
        /// Not implemented
        /// </summary>
        public IWebCookie Cookie
        {
            get
            {
                throw new NotSupportedException();
            }
        }

        public void Sleep(int milliseconds)
        {
            System.Threading.Thread.Sleep(milliseconds);
        }

        public void SyncAnyPage(YSODCheckTypes ysod)
        {
        }

        public void Navigate(string url, YSODCheckTypes ysod)
        {
        }

        public void NavigateWithTimeoutRetry(string url, int timeoutTryCounter = 3, YSODCheckTypes ysodCheck = YSODCheckTypes.CheckForYSOD)
        {
        }

        public NetworkTraffic NetworkTrafficLogger
        {
            get { throw new NotSupportedException(); }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
        }

        private class DumbCache : IDisposable
        {
            public void Dispose()
            {
            }
        }

        public void SetUrlModification(Func<String,String> func)
        {
            
        }
    }
}
